﻿using Appliaction.Dto.Inv;
using Appliaction.IAppServices.Inv;
using AutoMapper;
using Domain.Entitys.Base_Manage;
using Domain.Entitys.Inv;
using Domain.IRepositorys.Inv;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Appliaction.AppServices.Inv
{
    /// <summary>
    /// 其他入库单服务
    /// </summary>
    public class Inv_othwrServices : IInv_othwrServices
    {
        private readonly IInv_othwrRepository inv_OthwrRepository;

        private readonly IMapper mapper;

        public Inv_othwrServices(IInv_othwrRepository inv_OthwrRepository, IMapper mapper)
        {
            this.inv_OthwrRepository = inv_OthwrRepository;
            this.mapper = mapper;
        }


        /// <summary>
        /// 查看数据字典
        /// </summary>
        /// <param name="dict_value"></param>
        /// <param name="dict_type"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public Task<string> dict_data_Select(string dict_value, string dict_type)
        {
          return inv_OthwrRepository.dict_data_Select(dict_value, dict_type);
        }



        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name="searchKeyword"></param>
        /// <param name="othoutord_type"></param>
        /// <param name="currentPage"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public List<othwrSelectDto> GetOthwrWithDetailsAsync(string searchKeyword, string othoutord_type, int currentPage, int pageSize)
        {
          return inv_OthwrRepository.GetOthwrWithDetailsAsync(searchKeyword, othoutord_type, currentPage, pageSize);
        }
        /// <summary>
        /// 查询总数
        /// </summary>
        /// <param name="searchKeyword"></param>
        /// <param name="othoutord_type"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public Task<int> GetTotalCountAsync(string searchKeyword, string othoutord_type)
        {
            return inv_OthwrRepository.GetTotalCountAsync(searchKeyword, othoutord_type);
        }

        /// <summary>
        /// 根据单据编号查询 其他入库单信息的id,来添加详情    
        /// </summary>
        /// <param name="otgwr_code"></param>
        /// <returns></returns>
        public Task<int> inv_OthwrproddtlSelect_id(string otgwr_code) {

            return inv_OthwrRepository.inv_OthwrproddtlSelect_id(otgwr_code);
        }

        /// <summary>
        /// 根据其他入库单编号查询其他入库单详情信息
        /// </summary>
        /// <param name="Othwr_code"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public Task<List<Inv_othwrproddtl>> inv_OthwrproddtlSelect(string Othwr_code)
        {
            return inv_OthwrRepository.inv_OthwrproddtlSelect(Othwr_code);
        }
        /// <summary>
        /// 查询数据字典
        /// </summary>
        /// <param name="dict_value"></param>
        /// <param name="dict_type"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public Task<List<Sys_Dict_Data>> inv_othwr_SelectData(string dict_value, string dict_type)
        {
            return inv_OthwrRepository.inv_othwr_SelectData(dict_value, dict_type);
        }
        /// <summary>
        /// 查询仓库信息
        /// </summary>
        /// <param name="Othwr_code"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public Task<List<Inv_othwr>> inv_othwr_SelectWeahouse(string Othwr_code)
        {
            return inv_OthwrRepository.inv_othwr_SelectWeahouse(Othwr_code);
        }
        /// <summary>
        /// 库存调拨查询
        /// </summary>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public List<Inv_othwr> Inv_othwrall_trf()
        {
            return inv_OthwrRepository.Inv_othwrall_trf();
        }
        /// <summary>
        /// 库存盘点查询
        /// </summary>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public List<Inv_othwr> Inv_othwrall_qty()
        {
            return inv_OthwrRepository.Inv_othwrall_qty();
        }
        /// <summary>
        /// 添加其他入库单
        /// </summary>
        /// <param name="inv_OthwrAdd"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public Task<int> Inv_othwr_Insert(Inv_othwrAddDto inv_OthwrAdd)
        {
            Inv_othwr  inv_Othwr = mapper.Map<Inv_othwr>(inv_OthwrAdd);
            return inv_OthwrRepository.Inv_othwr_Insert(inv_Othwr);
        }
        /// <summary>
        /// 添加其他入库单详情表的信息
        /// </summary>
        /// <param name="inv_Othwrproddtl"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<int> Inv_othproddetails(List<Inv_othwrproddtlAddDto> inv_OthwrproddtlAddDtoList)
        {
            // 转换为实体列表
            var entities = inv_OthwrproddtlAddDtoList.Select(dto => new Inv_othwrproddtl
            {
                Othwr_id = dto.Othwr_id,
                Pro_name = dto.Pro_name,
                Pro_code = dto.Pro_code,
                Pro_brand = dto.Pro_brand,
                unitmeas_id = dto.unitmeas_id,
                Othwrproddtl_numder = dto.Othwrproddtl_numder,
                Inventory_numder = dto.Inventory_numder,
                Pro_model = dto.Pro_model,
                location_code = dto.location_code,
                location_name = dto.location_name,
                Othwrproddtl_yuan = dto.Othwrproddtl_yuan, // 这里应该是int?
                Othwrproddtl_time = dto.Othwrproddtl_time,
                pro_cost_price = dto.pro_cost_price,
                pro_sale_price = dto.pro_sale_price,
                stock_entry_no=dto.stock_entry_no,
                Vendor_code=dto.Vendor_code,
                Vendor_name=dto.Vendor_name,
              
            }).ToList();

            return await inv_OthwrRepository.Inv_othproddetails(entities);
        }
        /// <summary>
        /// 删除其他入库单
        /// </summary>
        /// <param name="othwr_id"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public Task<int> Inv_othwr_delete(int othwr_id)
        {
            return inv_OthwrRepository.Inv_othwr_delete(othwr_id);
        }
        /// <summary>
        /// 修改其他入库单审核信息
        /// </summary>
        /// <param name="othwr_code"></param>
        /// <param name="Othwr_audit_by"></param>
        /// <param name="Othwr_audit_time"></param>
        /// <param name="othwr_audit_statua"></param>
        /// <param name="othwr_audit_opinion"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public Task<int> Inv_othwr_examineUpdate(Inv_Update_othwrtDto inv_Update_othwrtDto)
        {
            Inv_othwr inv_othwr = mapper.Map<Inv_othwr>(inv_Update_othwrtDto);
            return inv_OthwrRepository.Inv_othwr_examineUpdate(inv_othwr);
        }
        /// <summary>
        /// 修改入库单和同一时间执行添加修改入库单详情
        /// </summary>
        /// <param name="inv_OthwrUpdateDto"></param>
        /// <param name="entities"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public Task<int> Inv_othwr_Update(Inv_othwrUpdateMerge inv_OthwrUpdateMerge)
        {
            Inv_othwr inv_othwr = mapper.Map<Inv_othwr>(inv_OthwrUpdateMerge.inv_OthwrUpdateDto);
            return inv_OthwrRepository.Inv_othwr_Update(inv_othwr, inv_OthwrUpdateMerge.inv_Othwrproddtls);
        }
        /// <summary>
        ///  根据入库单号去修改入库单的状态
        /// </summary>
        /// <param name="othwr_code"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public Task<int> Inv_othwr_Update_othwr_staus(string othwr_code)
        {
            return inv_OthwrRepository.Inv_othwr_Update_othwr_staus(othwr_code);
        }
        /// <summary>
        ///  根据入库单号去修改入库单的状态--判断,期初
        /// </summary>
        /// <param name="othwr_code"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public Task<int> Inv_othwr_Update_othwr_staus_pd(string othwr_code)
        {
            return inv_OthwrRepository.Inv_othwr_Update_othwr_staus_pd(othwr_code);
        }
    }
}
